// -----------------------------------------------
// Author:     code34 nicolas_boiteux@yahoo.fr
// Edited by:  Neumatic
// Warcontext: Fast time effect
// -----------------------------------------------

private [
	"_hour",
	"_minute",
	"_currenthour",
	"_currentminute",
	"_done",
	"_original",
	"_cible",
	"_cibleclockformat",
	"_clock"
];

_hour   = wcdate select 3;
_minute = wcdate select 4;

_done = false;
_cibleclockformat = [_hour, _minute] call WC_fnc_clockformat;

if (wcskiptime == 1) then {
	waitUntil {vehicle player == player};
	waitUntil {isNull wccam};

	wccam = player;
	wcadvancetodate = wcdate;

	setViewDistance 1500;
	wccameffect = ppEffectCreate ["ColorCorrections", 1999];
	wccameffect ppEffectEnable true;
	wccameffect ppEffectAdjust [0.5, 0.7, 0.0, [1.0, 1.0, 1.0, 0.0], [1.0, 1.0, 1.0, 0.0], [1.0, 1.0, 1.0, 1.0]];
	wccameffect ppEffectCommit 0;

	_original = dateToNumber date;
	_cible = dateToNumber wcdate;

	if (((_cible - _original) < 0.000015) or {((_original - _cible) > 0.000001)}) then {
		setDate wcdate;
		_done = true;
		_currenthour   = date select 3;
		_currentminute = date select 4;
		_clock = [_currenthour, _currentminute] call WC_fnc_clockformat;
	};

	while {!_done} do {
		_currenthour   = date select 3;
		_currentminute = date select 4;
		_clock = [_currenthour, _currentminute] call WC_fnc_clockformat;
		if !(_hour == _currenthour) then {
			skipTime 0.009;
		} else {
			setDate wcdate;
			_done = true;
			_currenthour   = date select 3;
			_currentminute = date select 4;
			_clock = [_currenthour, _currentminute] call WC_fnc_clockformat;
		};
		hintSilent format ["Fast time: %1 -> %2 \nPress Tab key to skip fast time", _clock, _cibleclockformat];
		sleep 0.0005;
	};

	ppEffectDestroy wccameffect;
	setViewDistance wcviewdist;
	wccam = objNull;
	wcadvancetodate = nil;
};

// If instant fast forward
if (wcskiptime == 2) then {
	setDate wcdate;
	_currenthour   = date select 3;
	_currentminute = date select 4;
	_clock = [_currenthour, _currentminute] call WC_fnc_clockformat;
	hintSilent format["Fast time: %1", _clock];
};